import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormControl, FormGroup} from '@angular/forms';
import {FormValidatorService} from 'great-ngform';

@Component({
  selector: 'app-decimal',
  templateUrl: './decimal.component.html',
  styleUrls: ['./decimal.component.less']
})
export class DecimalComponent implements OnInit {

  form: FormGroup;

  constructor(
    private fb: FormBuilder,
    private formValidatorService: FormValidatorService
  ) {
  }

  ngOnInit() {
    this.form = this.fb.group({
      decimal: new FormControl(null, [
        this.formValidatorService.decimal()
      ]),
      // 必须2位小数校验
      decimal1: [null, [this.formValidatorService.decimal({scale: 2})]],
      // 最多2位小数校验
      decimal2: [null, [this.formValidatorService.decimal({maxScale: 2})]],
      // 最少2位小数校验
      decimal3: [null, [this.formValidatorService.decimal({minScale: 2})]],
      // 必须2-3位小数
      decimal4: [null, [this.formValidatorService.decimal({minScale: 2, maxScale: 3})]],
      // 只能输入1-100之间的数字
      decimal5: [null, [this.formValidatorService.decimal({min: 1, max: 100})]],
      // 必须2-3位小数，且在1-100之间的数字
      decimal6: [null, [this.formValidatorService.decimal({minScale: 2, maxScale: 3, min: 1, max: 100})]],
      decimal7: [null, [this.formValidatorService.decimal({min: 100})]],
      decimal8: [null, [this.formValidatorService.decimal({max: 100})]],
      decimal9: [null, [this.formValidatorService.decimal({greaterThan: 100})]],
      decimal10: [null, [this.formValidatorService.decimal({lessThan: 100})]],
    });
  }

}
